[TT-16980] Fix pgx v5 breaking change when postgres.prefer_simple_protocol is set to true#970
[TT-16980] Fix pgx v5 breaking change when postgres.prefer_simple_protocol is set to true#970buraksezer wants to merge 3 commits intomasterfrom
Conversation
…tocol is set to true
|
This PR addresses a breaking change from the The solution avoids modifying shared data structures and instead operates at the database driver level. The To validate the fix, a new integration test, Files Changed Analysis
Architecture & Impact Assessment
sequenceDiagram |
✅ Security Check PassedNo security issues found – changes LGTM. Architecture Issues (1)
✅ Security Check PassedNo security issues found – changes LGTM. \n\nArchitecture Issues (1)
✅ Quality Check PassedNo quality issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2026-04-17T12:06:05.466Z | Triggered by: pr_updated | Commit: a66909a 💡 TIP: You can chat with Visor using |
This is misleading. |
|
|
Closed this PR to make the QA process easier. The bug only appears with this go.mod file: https://github.com/TykTechnologies/tyk-pump/pull/959/changes#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6 |


PR for https://tyktech.atlassian.net/browse/TT-16980
The proposed solution(
BeforeCreate+SetColumn) didn't work because GORM'sConvertToCreateValuesreads field values viafield.ValueOf(), which uses reflection to returnfieldValue.Interface(). Since the struct field type istime.Month, the value always reaches pgx astime.Monthregardless of whatSetColumnwrote. Go's reflection preserves the named type.Another possible solution might be to change the data type of
Monthfield inAnalyticsRecord. The current type istime.Month, if we create a new new type that implementsdriver.Valuerbut it is a potential breaking change and requires update across all Tyk components other potentials dependents.Implemented solution: In
pumps/sql.go, I replaced the postgres case inDialect()to build the*sql.DBourselves viastdlib.OpenDBwith anOptionAfterConnectcallback.On each new connection, we prepend a custom
TryWrapEncodePlanFuncto the encode plan chain that interceptstime.Monthand converts it to int before pgx'sfmt.Stringerwrapper can fire. I also replicate the timezone extraction logic fromgorm.io/driver/postgresto avoid behavioral regression, and pass the pre-built*sql.DBto GORM viapostgres.Config{Conn: sqlDB}.I have also added a test named
TestSQLWriteData_PreferSimpleProtocol_Month, before the fix that test was failing.How to run tests: